package com.zhl.media.app.mvp.ui.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.os.Message;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ExpandableListView;

import com.jess.arms.base.BaseFragment;
import com.jess.arms.di.component.AppComponent;
import com.jess.arms.utils.ArmsUtils;

import com.zhl.media.app.di.component.DaggerMyTaskComponent;
import com.zhl.media.app.model.Building;
import com.zhl.media.app.model.GroupInfo;
import com.zhl.media.app.model.Project;
import com.zhl.media.app.model.Unit;
import com.zhl.media.app.mvp.adapter.GroupAdapter;
import com.zhl.media.app.mvp.contract.MyTaskContract;
import com.zhl.media.app.mvp.presenter.MyTaskPresenter;

import com.zhl.media.app.R;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

import static com.jess.arms.utils.Preconditions.checkNotNull;


public class MyTaskFragment extends BaseFragment<MyTaskPresenter> implements MyTaskContract.View {

    public static MyTaskFragment newInstance() {
        MyTaskFragment fragment = new MyTaskFragment();
        return fragment;
    }

    @BindView(R.id.expandableListView)
    ExpandableListView expandableListView;

    List<GroupInfo> groupInfos;

    @Override
    public void setupFragmentComponent(@NonNull AppComponent appComponent) {
        DaggerMyTaskComponent.builder().appComponent(appComponent).view(this).build().inject(this);
    }

    @Override
    public View initView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragment_my_task, container, false);
    }

    @Override
    public void initData(@Nullable Bundle savedInstanceState) {
        data();
        GroupAdapter adapter = new GroupAdapter(getActivity(),groupInfos);
        expandableListView.setAdapter(adapter);

        expandableListView.expandGroup(0);
        expandableListView.expandGroup(1);
    }

    private void data() {
        groupInfos = new ArrayList<>();
        GroupInfo bqrw = new GroupInfo();
        bqrw.setId("0");
        bqrw.setName("本期任务");
        List<Project> bprojects = new ArrayList<>();
        bqrw.setProjects(bprojects);

        GroupInfo fbqrw = new GroupInfo();
        fbqrw.setId("0");
        fbqrw.setName("本期未涉及任务的楼盘");
        List<Project> fprojects = new ArrayList<>();

        List<Unit> fu = new ArrayList<>();
        fu.add(new Unit("1","一单元",1,1,"2","2"));
        fu.add(new Unit("1","二单元",1,1,"2","2"));
        fu.add(new Unit("1","三单元",1,1,"2","2"));
        fu.add(new Unit("1","三单元",1,1,"2","2"));
        fu.add(new Unit("1","三单元",1,1,"2","2"));
        fu.add(new Unit("1","三单元",1,1,"2","2"));
        fu.add(new Unit("1","三单元",1,1,"2","2"));
        fu.add(new Unit("1","三单元",1,1,"2","2"));
        fu.add(new Unit("1","三单元",1,1,"2","2"));
        fu.add(new Unit("1","三单元",1,1,"2","2"));
        fu.add(new Unit("1","三单元",1,1,"2","2"));
        fu.add(new Unit("1","三单元",1,1,"2","2"));
        fu.add(new Unit("1","三单元",1,1,"2","2"));
        fu.add(new Unit("1","三单元",1,1,"2","2"));
        fu.add(new Unit("1","三单元",1,1,"2","2"));
        fu.add(new Unit("1","三单元",1,1,"2","2"));
        fu.add(new Unit("1","三单元",1,1,"2","2"));
        fu.add(new Unit("1","三单元",1,1,"2","2"));
        List<Building> fb = new ArrayList<>();
        Building building = new Building("1", "A座", 1, 1, "b");
        building.setUnits(fu);
        fb.add(building);
        fb.add(new Building("1", "A座", 1, 1, "b"));
        fb.add(new Building("1", "A座", 1, 1, "b"));
        fb.add(new Building("1", "A座", 1, 1, "b"));
        fb.add(new Building("1", "A座", 1, 1, "b"));
        fb.add(new Building("1", "A座", 1, 1, "b"));
        fb.add(new Building("1", "A座", 1, 1, "b"));

        Project p1 = new Project("1","鲁能城",1,1,1,1,1,1,1);
        p1.setBuildings(fb);
        fprojects.add(p1);
        fprojects.add(new Project("1","鲁能城",1,1,1,1,1,1,1));


        fbqrw.setProjects(fprojects);
        groupInfos.add(bqrw);
        groupInfos.add(fbqrw);
    }

    @Override
    public void setData(@Nullable Object data) {

    }

    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }

    @Override
    public void showMessage(@NonNull String message) {
        checkNotNull(message);
        ArmsUtils.snackbarText(message);
    }

    @Override
    public void launchActivity(@NonNull Intent intent) {
        checkNotNull(intent);
        ArmsUtils.startActivity(intent);
    }

    @Override
    public void killMyself() {

    }
}
